import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import svgLoader from 'vite-svg-loader'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    svgLoader()
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      "@components": fileURLToPath(new URL("./src/components", import.meta.url)),
      "@assets": fileURLToPath(new URL("./src/assets", import.meta.url)),
    },
  },
  optimizeDeps: {
    include: [
      '@vicons/material',
      '@vicons/tabler',
      '@vicons/carbon',
      '@vicons/antd',
      '@vicons/fluent',
      '@vicons/fa',
      '@vicons/ionicons5',
      '@vicons/ionicons4'
    ],
    esbuildOptions: {
      target: 'esnext'
    }
  },
  build: {
    commonjsOptions: {
      include: [/@vicons/, /node_modules/],
      transformMixedEsModules: true
    }
  },
  server: {
    host: "localhost",
    port: 8093,
    open: true,
    proxy: {
      "^/api/": {
        target: "http://127.0.0.1:8094", // 后端服务实际地址
        changeOrigin: true, //开启代理
        ws: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  }
})
